object Translator {
  // 中文到英文的映射
  private val chineseToEnglish = Map(
    "苹果" -> "apple",
    "香蕉" -> "banana",
    "猫" -> "cat",
    "狗" -> "dog",
    "书" -> "book"
  )

  // 反转映射生成英文到中文的Map
  private val englishToChinese = chineseToEnglish.map(_.swap)

  // 翻译函数
  def translate(input: String): String = {
    chineseToEnglish.get(input) match {
      case Some(eng) => eng
      case None =>
        englishToChinese.get(input) match {
          case Some(ch) => ch
          case None => s"『$input』没有找到对应的翻译"
        }
    }
  }

  // 主程序
  def main(args: Array[String]): Unit = {
    println("翻译工具（输入 exit 退出）")
    var running = true
    while (running) {
      print("请输入词语: ")
      val input = scala.io.StdIn.readLine().trim
      if (input.equalsIgnoreCase("exit")) {
        running = false
        println("感谢使用！")
      } else if (input.nonEmpty) {
        println(translate(input))
      }
    }
  }
}